package online.inote.graphql.modules.book.resolver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.coxautodev.graphql.tools.GraphQLQueryResolver;

import online.inote.graphql.common.base.BaseQueryResolver;
import online.inote.graphql.modules.author.service.AuthorService;
import online.inote.graphql.modules.book.entity.BookEntity;

/**
 * @description: TODO
 * @author XQF.Sui
 * @created 2019年4月20日 上午3:04:42
 * @version 1.0
 */
@Component
public class BookQueryResolver extends BaseQueryResolver<BookEntity, Integer> implements GraphQLQueryResolver {

	@Autowired
	private AuthorService authorService;

	public BookEntity queryBooks() {

		BookEntity book = service.selectByPrimaryKey(1);
		
		if (book != null && book.getAuthorId() != null) {
			book.setAuthor(authorService.selectByPrimaryKey(book.getAuthorId()));
		}
		
		return book;
	}
}